home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_051 / bison / parser < prev    next >
Text File  |  1992-05-06  |  7KB  |  339 lines

  1.  
  2. #include "b.stype.h"
  3.  
  4. extern int timeclock;
  5.  
  6.  
  7. int yyerror;        /*  Yyerror and yycost are set by guards.    */
  8. int yycost;        /*  If yyerror is set to a nonzero value by a    */
  9.             /*  guard, the reduction with which the guard    */
  10.             /*  is associated is not performed, and the    */
  11.             /*  error recovery mechanism is invoked.    */
  12.             /*  Yycost indicates the cost of performing    */
  13.             /*  the reduction given the attributes of the    */
  14.             /*  symbols.                    */
  15.  
  16.  
  17. #define    YYACCEPT    return (0)
  18. #define    YYABORT        return (1)
  19.  
  20.  
  21. /*  YYMAXDEPTH indicates the size of the parser's state and value    */
  22. /*  stacks.                                */
  23.  
  24. #ifndef    YYMAXDEPTH
  25. #define    YYMAXDEPTH    250
  26. #endif
  27.  
  28. /*  YYMAXRULES must be at least as large as the number of rules that    */
  29. /*  could be placed in the rule queue.  That number could be determined    */
  30. /*  from the grammar and the size of the stack, but, as yet, it is not.    */
  31.  
  32. #ifndef    YYMAXRULES
  33. #define    YYMAXRULES    100
  34. #endif
  35.  
  36. #ifndef    YYMAXBACKUP
  37. #define YYMAXBACKUP    100
  38. #endif
  39.  
  40.  
  41. short    yyss[YYMAXDEPTH];    /*  the state stack            */
  42. YYSTYPE    yyvs[YYMAXDEPTH];    /*  the semantic value stack        */
  43. YYLTYPE yyls[YYMAXDEPTH];    /*  the location stack            */
  44. short    yyrq[YYMAXRULES];    /*  the rule queue            */
  45. int    yychar;            /*  the lookahead symbol        */
  46.  
  47. YYSTYPE    yylval;            /*  the semantic value of the        */
  48.                 /*  lookahead symbol            */
  49.  
  50. YYSTYPE yytval;            /*  the semantic value for the state    */
  51.                 /*  at the top of the state stack.    */
  52.  
  53. YYSTYPE yyval;            /*  the variable used to return        */
  54.                 /*  semantic values from the action    */
  55.                 /*  routines                */
  56.  
  57. YYLTYPE yylloc;        /*  location data for the lookahead    */
  58.                 /*  symbol                */
  59.  
  60. YYLTYPE yytloc;        /*  location data for the state at the    */
  61.                 /*  top of the state stack        */
  62.  
  63.  
  64. int    yynunlexed;
  65. short    yyunchar[YYMAXBACKUP];
  66. YYSTYPE    yyunval[YYMAXBACKUP];
  67. YYLTYPE yyunloc[YYMAXBACKUP];
  68.  
  69. short *yygssp;            /*  a pointer to the top of the state    */
  70.                 /*  stack; only set during error    */
  71.                 /*  recovery.                */
  72.  
  73. YYSTYPE *yygvsp;        /*  a pointer to the top of the value    */
  74.                 /*  stack; only set during error    */
  75.                 /*  recovery.                */
  76.  
  77. YYLTYPE *yyglsp;        /*  a pointer to the top of the        */
  78.                 /*  location stack; only set during    */
  79.                 /*  error recovery.            */
  80.  
  81.  
  82. /*  Yyget is an interface between the parser and the lexical analyzer.    */
  83. /*  It is costly to provide such an interface, but it avoids requiring    */
  84. /*  the lexical analyzer to be able to back up the scan.        */
  85.  
  86. yyget()
  87. {
  88.   if (yynunlexed > 0)
  89.     {
  90.       yynunlexed--;
  91.       yychar = yyunchar[yynunlexed];
  92.       yylval = yyunval[yynunlexed];
  93.       yylloc = yyunloc[yynunlexed];
  94.     }
  95.   else if (yychar <= 0)
  96.     yychar = 0;
  97.   else
  98.     {
  99.       yychar = yylex();
  100.       if (yychar < 0)
  101.     yychar = 0;
  102.       else yychar = YYTRANSLATE(yychar);
  103.     }
  104. }
  105.  
  106.  
  107.  
  108. yyunlex(chr, val, loc)
  109. int chr;
  110. YYSTYPE val;
  111. YYLTYPE loc;
  112. {
  113.   yyunchar[yynunlexed] = chr;
  114.   yyunval[yynunlexed] = val;
  115.   yyunloc[yynunlexed] = loc;
  116.   yynunlexed++;
  117. }
  118.  
  119.  
  120.  
  121. yyrestore(first, last)
  122. register short *first;
  123. register short *last;
  124. {
  125.   register short *ssp;
  126.   register short *rp;
  127.   register int symbol;
  128.   register int state;
  129.   register int tvalsaved;
  130.  
  131.   ssp = yygssp;
  132.   yyunlex(yychar, yylval, yylloc);
  133.  
  134.   tvalsaved = 0;
  135.   while (first != last)
  136.     {
  137.       symbol = yystos[*ssp];
  138.       if (symbol < YYNTBASE)
  139.     {
  140.       yyunlex(symbol, yytval, yytloc);
  141.       tvalsaved = 1;
  142.       ssp--;
  143.     }
  144.  
  145.       ssp--;
  146.  
  147.       if (first == yyrq)
  148.     first = yyrq + YYMAXRULES;
  149.  
  150.       first--;
  151.  
  152.       for (rp = yyrhs + yyprhs[*first]; symbol = *rp; rp++)
  153.     {
  154.       if (symbol < YYNTBASE)
  155.         state = yytable[yypact[*ssp] + symbol];
  156.       else
  157.         {
  158.           state = yypgoto[symbol - YYNTBASE] + *ssp;
  159.  
  160.           if (state >= 0 && state <= YYLAST && yycheck[state] == *ssp)
  161.         state = yytable[state];
  162.           else
  163.         state = yydefgoto[symbol - YYNTBASE];
  164.         }
  165.  
  166.       *++ssp = state;
  167.     }
  168.     }
  169.  
  170.   if ( ! tvalsaved && ssp > yyss)
  171.     {
  172.       yyunlex(yystos[*ssp], yytval, yytloc);
  173.       ssp--;
  174.     }
  175.  
  176.   yygssp = ssp;
  177. }
  178.  
  179.  
  180.  
  181. int
  182. yyparse()
  183. {
  184.   register int yystate;
  185.   register int yyn;
  186.   register short *yyssp;
  187.   register short *yyrq0;
  188.   register short *yyptr;
  189.   register YYSTYPE *yyvsp;
  190.  
  191.   int yylen;
  192.   YYLTYPE *yylsp;
  193.   short *yyrq1;
  194.   short *yyrq2;
  195.  
  196.   yystate = 0;
  197.   yyssp = yyss - 1;
  198.   yyvsp = yyvs - 1;
  199.   yylsp = yyls - 1;
  200.   yyrq0 = yyrq;
  201.   yyrq1 = yyrq0;
  202.   yyrq2 = yyrq0;
  203.  
  204.   yychar = yylex();
  205.   if (yychar < 0)
  206.     yychar = 0;
  207.   else yychar = YYTRANSLATE(yychar);
  208.  
  209. yynewstate:
  210.  
  211.   if (yyssp >= yyss + YYMAXDEPTH - 1)
  212.     {
  213.       yyabort("Parser Stack Overflow");
  214.       YYABORT;
  215.     }
  216.  
  217.   *++yyssp = yystate;
  218.  
  219. yyresume:
  220.  
  221.   yyn = yypact[yystate];
  222.   if (yyn == YYFLAG)
  223.     goto yydefault;
  224.  
  225.   yyn += yychar;
  226.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar)
  227.     goto yydefault;
  228.  
  229.   yyn = yytable[yyn];
  230.   if (yyn < 0)
  231.     {
  232.       yyn = -yyn;
  233.       goto yyreduce;
  234.     }
  235.   else if (yyn == 0)
  236.     goto yyerrlab;
  237.  
  238.   if (yyn == YYFINAL)
  239.     YYACCEPT;
  240.  
  241.   yystate = yyn;
  242.  
  243.   yyptr = yyrq2;
  244.   while (yyptr != yyrq1)
  245.     {
  246.       yyn = *yyptr++;
  247.       yylen = yyr2[yyn];
  248.       yyvsp -= yylen;
  249.       yylsp -= yylen;
  250.  
  251.       yyguard(yyn, yyvsp, yylsp);
  252.       if (yyerror)
  253.     goto yysemerr;
  254.  
  255.       yyaction(yyn, yyvsp, yylsp);
  256.       *++yyvsp = yyval;
  257.  
  258.       yylsp++;
  259.       if (yylen == 0)
  260.     {
  261.       yylsp->timestamp = timeclock;
  262.       yylsp->first_line = yytloc.first_line;
  263.       yylsp->first_column = yytloc.first_column;
  264.       yylsp->last_line = (yylsp-1)->last_line;
  265.       yylsp->last_column = (yylsp-1)->last_column;
  266.       yylsp->text = 0;
  267.     }
  268.       else
  269.     {
  270.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  271.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  272.     }
  273.       
  274.       if (yyptr == yyrq + YYMAXRULES)
  275.         yyptr = yyrq;
  276.     }
  277.  
  278.   yyrq2 = yyptr;
  279.   yyrq1 = yyrq0;
  280.  
  281.   *++yyvsp = yytval;
  282.   *++yylsp = yytloc;
  283.   yytval = yylval;
  284.   yytloc = yylloc;
  285.   yyget();
  286.  
  287.   goto yynewstate;
  288.  
  289. yydefault:
  290.  
  291.   yyn = yydefact[yystate];
  292.   if (yyn == 0)
  293.     goto yyerrlab;
  294.  
  295. yyreduce:
  296.  
  297.   *yyrq0++ = yyn;
  298.  
  299.   if (yyrq0 == yyrq + YYMAXRULES)
  300.     yyrq0 = yyrq;
  301.  
  302.   if (yyrq0 == yyrq2)
  303.     {
  304.       yyabort("Parser Rule Queue Overflow");
  305.       YYABORT;
  306.     }
  307.  
  308.   yyssp -= yyr2[yyn];
  309.   yyn = yyr1[yyn];
  310.  
  311.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  312.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  313.     yystate = yytable[yystate];
  314.   else
  315.     yystate = yydefgoto[yyn - YYNTBASE];
  316.  
  317.   goto yynewstate;
  318.  
  319. yysemerr:
  320.   *--yyptr = yyn;
  321.   yyrq2 = yyptr;
  322.   yyvsp += yyr2[yyn];
  323.  
  324. yyerrlab:
  325.  
  326.   yygssp = yyssp;
  327.   yygvsp = yyvsp;
  328.   yyglsp = yylsp;
  329.   yyrestore(yyrq0, yyrq2);
  330.   yyrecover();
  331.   yystate = *yygssp;
  332.   yyssp = yygssp;
  333.   yyvsp = yygvsp;
  334.   yyrq0 = yyrq;
  335.   yyrq1 = yyrq0;
  336.   yyrq2 = yyrq0;
  337.   goto yyresume;
  338. }
  339.